<template>
	<view class="wedding-info">
		<view class="c-row-box">
			<view class="c-row-head"><view class="c-row-title">婚庆信息</view></view>
			<view class="c-row-item">
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							承办公司
						</view>
						<view class="col-text">
							<picker mode="selector" :range="companyList" range-key="title" @change="weddingCompanyChange" :disabled="isPreview">
								<view>{{ selectedCompany }}</view>
							</picker>
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							选择套餐
						</view>
						<view class="col-text">
							<picker mode="selector" :range="weddingPackageList" range-key="title" @change="weddingPackageChange" :disabled="isPreview">
								<view>{{ selectedWeddingPackage }}</view>
							</picker>
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							套餐价
						</view>
						<view class="col-text">
							<input type="text" v-model="weddingParams.wedding_package_price" :disabled="isPreview" placeholder="请输入" @input="weddingChange" />
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">优惠价</view>
						<view class="col-text">
							<input type="text" v-model="weddingParams.wedding_discount" :disabled="isPreview" placeholder="请输入" @input="weddingChange" />
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">
							<text style="color: red;">*</text>
							实收价
						</view>
						<view class="col-text">
							<text>{{ weddingParams.wedding_totals }}</text>
						</view>
					</view>
				</view>
				<view class="c-row c-row-list">
					<view class="c-row-col c-row-col-list-item">
						<view class="col-title">产品编号</view>
						<view class="col-text"><input type="text" v-model="weddingParams.product_no" :disabled="isPreview" placeholder="请输入" /></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import dictionary from '@/utils/dictionary.js';

export default {
	props: {
		isPreview: {
			type: Boolean,
			default() {
				return false;
			}
		},
		order: {
			type: Object,
			default() {
				return {};
			}
		},
		weddingParams: {
			type: Object,
			default() {
				return {};
			}
		},
	},
	data() {
		return {};
	},
	computed: {
		companyList: function() {
			let companyList = dictionary.getPicker('companyList');
			companyList = companyList.filter(ele => ele.is_valid == 1);
			return companyList;
		},
		selectedCompany: function() {
			return dictionary.getPickerTitle('companyList', this.weddingParams.company_id, '请选择');
		},
		weddingPackageList: function() {
			let weddingPackageList = dictionary.getPicker('weddingPackageList');
			return weddingPackageList;
		},
		selectedWeddingPackage() {
			return dictionary.getPickerTitle('weddingPackageList', this.weddingParams.wedding_package_id, '请选择');
		}
	},
	beforeMount() {
		this.dictionary = dictionary;
	},
	methods: {
		// 承办公司变化
		weddingCompanyChange(e) {
			let index = e.target.value;
			this.weddingParams.company_id = this.companyList[index].id;
		},
		// 婚庆套餐变化
		weddingPackageChange(e) {
			let index = e.target.value;
			this.weddingParams.wedding_package_id = this.weddingPackageList[index].id;
		},

		// 获取婚庆实收
		weddingChange() {
			let that = this;
			that.weddingParams.wedding_totals = (
				parseFloat(that.weddingParams.wedding_package_price === '' ? 0 : that.weddingParams.wedding_package_price) -
				parseFloat(that.weddingParams.wedding_discount === '' ? 0 : that.weddingParams.wedding_discount)
			).toFixed(2);
			that.$emit('getOrderTotals');
		}
	}
};
</script>
<style lang="less">
@import url('../../components/common.less');
@import url('../common/common.less');
</style>

